package com.ding.vod.controller;

import com.ding.commonutils.Result;
import com.ding.vod.service.VodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/eduvod/video")
@CrossOrigin
public class VodController {

    @Autowired
    private VodService vodService;

    //上传视频到阿里云
    @PostMapping("uploadVideo")
    public Result uploadVideo(MultipartFile file) throws IOException {
         String videoId = vodService.uploadVideo(file);
        return Result.ok().data("id",videoId);
    }

    //删除阿里云视频
    @DeleteMapping("delVideo/{videoId}")
    public Result  delVideo(@PathVariable String videoId){
        int num = vodService.delVideo(videoId);
        if(num>0){
            return Result.ok();
        }else{
            return Result.error();
        }
    }

    //删除多个阿里云视频的方法
    //参数是多个视频id,List videoIdList
    @DeleteMapping("deletevideo/delete")
    public Result deleteBatch(@RequestParam("videoIdList") List videoIdList){
      vodService.removeAllVideo(videoIdList);

        return Result.ok();
    }

}
